package cn.szzsi._web;

import cn.szzsi.common.bean.dto.Msg;
import cn.szzsi.common.kit.BackUtil;
import cn.szzsi.common.model.Member;
import cn.szzsi.common.model.TocashBank;
import com.alibaba.fastjson.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * 提现银行卡管理
 * Created by yuanzheng on 2016/11/29.
 */
public class CashingBankController extends BaseWebController<TocashBank>{
    private String shopId;//用户的shopId就是商户的id
    public void list(){
        //shopId=getLoginMember().getStr("shopId");//用户的shopId对应商户的id(uid),商户的shopId为0
        String returnUrl=getPara("returnUrl");
        String memberId=getLoginMember().getId();
        setAttr("bank", TocashBank.getByMid(memberId));
        setAttr("returnurl","returnurl");
        setAttr("from","conform");
        setAttr("useWeixinAddr",true);
        setAttr("returnUrl",returnUrl);
        wapTemplatePath("tocashing_bank_list.html");
    }

    public void save(){
        Member member=getLoginMember();//当前登录用户
        String name=getPara("name");//提现人姓名
        String cardNumber=getPara("cardNumber");//换行卡号
        String cardCount=getPara("cardCount");//开户行名称
        String cardAddress=getPara("cardAddress");//开户行地址
        String idNumber=getPara("idNumber");//身份证号
        String aliPayAccount=getPara("aliPayAccount");//支付宝账号
        String weChatAccount=getPara("weChatAccount");
        TocashBank tocashBank=TocashBank.saveCashingBank(member.getStr("id"),name,cardNumber,cardCount,cardAddress,idNumber,aliPayAccount,weChatAccount);
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("bankId",tocashBank.getId());
        renderJson(BackUtil.success("",jsonObject));
    }

    public void delete(){
        Integer id=getParaToInt("id");
        TocashBank toCashingBank= TocashBank.dao.findById(id);
        toCashingBank.delete();
        renderJson(BackUtil.success());
    }
}
